package com.mazha.rabbitmq.common.thread;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置
 *
 * @author leizi
 * @date 2023/12/10
 */
@Configuration
public class ThreadPoolConfig {

    /**
     * 消息监听线程池
     *
     * @return
     */
    @Bean("chatSpeakThreadPool")
    public ThreadPoolExecutor chatMessageListenerThread() {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,
                10,
                100,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue(100),
                new ThreadPoolExecutor.DiscardOldestPolicy());
        return threadPoolExecutor;
    }

}
